﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OutlookTags.Controls
{
    public partial class CategoryAutocompleteControl : UserControl
    {
        public CategoryAutocompleteControl()
        {
            InitializeComponent();
        }

        public void AssignAutoCompleteSource(IListSource source)
        {
            autoCompleteListBox.DataSource = source;                        
        }

        public void RefresAutoCompleteSource()
        {
            if (autoCompleteListBox.DataSource != null)
            {
                ((CurrencyManager)autoCompleteListBox.BindingContext[autoCompleteListBox.DataSource]).Refresh();
            }
        }


        public string SelectedText
        {
            get 
            {
                if(autoCompleteListBox.SelectedIndices.Count > 0)
                    return autoCompleteListBox.SelectedItem.ToString();
                return "";
            }
        }

        public void Up()
        {
            if(autoCompleteListBox.SelectedIndices.Count  == 0)
                return;
            int idx = autoCompleteListBox.SelectedIndex - 1;
            if (idx >= 0)
                autoCompleteListBox.SelectedIndex = idx;
        }

        public void Down()
        {
            if (autoCompleteListBox.SelectedIndices.Count == 0)
                return;
            int idx = autoCompleteListBox.SelectedIndex + 1;
            if (idx < autoCompleteListBox.Items.Count)
                autoCompleteListBox.SelectedIndex = idx;
        }
    }
}
